/* @(#)alarm.hh
 * Time-stamp: <2009-02-23 21:03:13 root>
 * Copyright 2008 Julian Qian
 * Author: root@localhost.localdomain
 * Version: $Id: alarm.hh,v 0.0 2008/11/16 18:41:24 root Exp $
 * Keywords: 
 */

#ifndef _ALARM_H
#define _ALARM_H 1

#include "common.hh"

#include <map>
#include <string>

typedef std::map<devid_t, alarm_t> DEVID_PAIR;

class Wrapesms;
class Db;
class Heart;
class MutEX;

class Alarm {
public:
    static Alarm* theAlarm();
    static void endAlarm();

    void send_phone_alarm();
    void send_phone_alarm_(DEVID_PAIR &dp);
    void send_dev_alarm();
    void send_dev_alarm_(DEVID_PAIR& dlist);

    void queue_alarm(devid_t devid, alarm_t alarm);
    void queue_ctrl(devid_t devid, alarm_t alarm);
    
    // void runloop();
    alarm_t alarm_ctl(const char* als);
    
private:
    static Alarm* _theAlarm;

    Alarm();
    virtual ~Alarm();

    DEVID_PAIR* get_devlist();
    void clear_list(DEVID_PAIR& list);

    alarm_t alarm_result(alarm_t alarm);
    std::string alarm_str(alarm_t alarm);
    // void dispatcher(int signo);
    alarm_t parse_alarm(std::string str);
    std::string parse_devid(std::string str);
    
protected:    
    Wrapesms* _we;
    Db* _db;
    Heart* _ht;
    // Dispatch* _ds;
    MutEX* _mutdev;

    typedef std::map<std::string, std::string> WARN_PAIR;
    WARN_PAIR _wMsg;
    
    DEVID_PAIR _devList;
    DEVID_PAIR _alarmQueue;

    // alarm_t alarmCtl;
};


#endif /* _ALARM_H */

